<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var obj = {
        //     name:'张三',
        //     age:18,
        //     height:'181cm'
        // }

        // var arr = ['a','b','c'];



        // '{"name":"zhangsan","age":18,"height":"181cm"}';
        // '["a","b","c"]';

        // json本质是字符串 



        // js数据类型转json  

        var arrs = ['a','b','c','f'];
        var obj = {
            name:'张三',
            age:18,
            height:'181cm',
            child:{
                name:'李四',
                age:4,
                hobby:['吃饭','睡觉','挖也挖']
            }
        }
        // console.log(typeof arrs,typeof obj);


        // // json本质是字符串   string
        // var res1 = JSON.stringify(arrs);
        // var res2 = JSON.stringify(obj);
        // console.log(res1,typeof res1);
        // console.log(res2,typeof res2);


        // json格式转  js数据类型  
        var str1 = '["a","b","c","f"]';
        var obj1 = '{"name":"张三","age":18,"height":"181cm","child":{"name":"李四","age":4,"hobby":["吃饭","睡觉","挖也挖"]}}';


        console.log(typeof str1,typeof obj1);
        var res3 = JSON.parse(str1);
        var res4 = JSON.parse(obj1);
        console.log(res4,typeof res4);
        console.log(res3,typeof res3);


    </script>
</body>
</html>